package acwing;

import java.io.*;

public class ac829 {
    static int N = 100010;
    static int[] q = new int[N];
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    public static void main(String[] args) throws IOException {
        int m;
        int hh = 0, tt = -1;
        m = Integer.parseInt(in.readLine());
        while(m -- > 0){
            String[] str = in.readLine().split(" ");
            String op = str[0];
//            op = in.readLine();
            if (op.equals("push")) {
                int x = Integer.parseInt(str[1]);
//                x = Integer.parseInt(in.readLine());
                q[++ tt] = x;
            }else if (op.equals("pop")){
                hh ++ ;
            }else if (op.equals("empty")){
                out.println((hh <= tt ? "NO" : "YES"));
            }else {
                out.println(q[hh]);
            }
        }
        out.close();
    }
}
